/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author rj
 */
public class CheckForUnique {
 
    public static boolean checkAccountID(int value){
        boolean isValid = true;
        
        try {
            
     //       value = 3;
            DBConnection db = new DBConnection();
            Connection conn = db.getConnection();
            
            PreparedStatement stat = conn.prepareStatement("SELECT AccountID FROM user");
            ResultSet rs = stat.executeQuery();
            
            while(rs.next()){
                if(rs.getInt("AccountID") == value)
                    isValid = false;
                
            }
            
            conn.close();
        } catch (SQLException ex) {
            Logger.getLogger(CheckForUnique.class.getName()).log(Level.SEVERE, null, ex);
        }
        return isValid;
    }
    
    public static boolean checkTransactionID(int value){
        boolean isValid = true;
        
        try {
            
     //       value = 3;
            DBConnection db = new DBConnection();
            Connection conn = db.getConnection();
            
            PreparedStatement stat = conn.prepareStatement("SELECT TransactionID FROM transaction");
            ResultSet rs = stat.executeQuery();
            
            while(rs.next()){
                if(rs.getInt("TransactionID") == value)
                    isValid = false;
                
            }
            
            
            
        } catch (SQLException ex) {
            Logger.getLogger(CheckForUnique.class.getName()).log(Level.SEVERE, null, ex);
        }
        return isValid;
    }
    
    public static boolean checkProductID(int value){
        boolean isValid = true;
        
        try {
            
     //       value = 3;
            DBConnection db = new DBConnection();
            Connection conn = db.getConnection();
            
            PreparedStatement stat = conn.prepareStatement("SELECT ProductID FROM product");
            ResultSet rs = stat.executeQuery();
            
            while(rs.next()){
                if(rs.getInt("ProductID") == value)
                    isValid = false;
                
            }
            
        } catch (SQLException ex) {
            Logger.getLogger(CheckForUnique.class.getName()).log(Level.SEVERE, null, ex);
        }
        return isValid;
    }
    
    
    public static boolean checkFakeProductID(int value){
        boolean isValid = true;
        
        try {
            
     //       value = 3;
            DBConnection db = new DBConnection();
            Connection conn = db.getConnection();
            
            PreparedStatement stat = conn.prepareStatement("SELECT FakeProductID FROM productidtrack");
            ResultSet rs = stat.executeQuery();
            
            while(rs.next()){
                if(rs.getInt("FakeProductID") == value)
                    isValid = false;
                
            }
            
            
            
        } catch (SQLException ex) {
            Logger.getLogger(CheckForUnique.class.getName()).log(Level.SEVERE, null, ex);
        }
        return isValid;
    }
    
    public static boolean checkFakeAccountID(int value){
        boolean isValid = true;
        
        try {
            
     //       value = 3;
            DBConnection db = new DBConnection();
            Connection conn = db.getConnection();
            
            PreparedStatement stat = conn.prepareStatement("SELECT FakeAccountID FROM useridtrack");
            ResultSet rs = stat.executeQuery();
            
            while(rs.next()){
                if(rs.getInt("FakeAccountID") == value)
                    isValid = false;
                
            }
            
            conn.close();
            
        } catch (SQLException ex) {
            Logger.getLogger(CheckForUnique.class.getName()).log(Level.SEVERE, null, ex);
        }
        return isValid;
    }
    
    
    
}
